import {IModel} from "./IModel";
import {security} from "../units/encrypt";
import {ResponseData} from "./ResponseData";
import {setValidator} from "../decorator/setValidator";
import {maxAndMinLengthValidator} from "../validator/maxAndMinLengthValidator";
import {validatorEnum} from "../validator/validatorEnum";
import {getValidators} from "../decorator/getValidators";
import {mc_validatorResult} from "./mc_validatorResult";
/**
 * Created by ybjaa on 2017/6/23.
 */

/**
 * 根据原密码修改密码
 *
 * ms(实体类，和服务器交互的)
 *
 */
export class ms_resetPasswordFromSource implements IModel{

    @setValidator(validatorEnum.regularFail,
        "密码:只能为字母和数字以及特殊字符，不能出现中文,空格等字符。",security.passwordRegexp)
    @setValidator(validatorEnum.maxAndMinLength,"密码长度错误:",6,20)
    public sourcePassword:string="";

    @setValidator(validatorEnum.regularFail,
        "密码:只能为字母和数字以及特殊字符，不能出现中文,空格等字符。",security.passwordRegexp)
    @setValidator(validatorEnum.maxAndMinLength,"新密码长度错误:",6,20)
    public newPassword:string="";

    @setValidator(validatorEnum.equalPropery,"和密码不匹配:","newPassword")
    public newInvalidPassword:string="";


    clone(): ms_resetPasswordFromSource {
        let model=new ms_resetPasswordFromSource();
        model.sourcePassword=this.sourcePassword;
        model.newPassword=this.newPassword;
        return model;
    }

    copyFrom(model: ms_resetPasswordFromSource): ms_resetPasswordFromSource {
        this.sourcePassword=model.sourcePassword;
        this.newPassword=model.newPassword;
        return this;
    }

    encryptSourcePassword():string{
        return security.encrypt(this.sourcePassword);
    }

    encryptNewPassword():string{
        return security.encrypt(this.newPassword);
    }


    @getValidators()
    public validator(result:boolean=true,result_validators:mc_validatorResult[]=null){

        let messages="";

        if(!result){
            messages=result_validators.map(v=>v.message).join("\r\n");
        }

        let validatorResult=new mc_validatorResult();

        validatorResult.result=result;
        validatorResult.message=messages;

        return validatorResult;

    }


}